/*
 *
 * SimplePCR1000 (Qt4) Version 1.x
 * Copyright (C) 2011  Tyler H. Jones (me@tylerjones.me)
 * http://www.thebasementserver.com/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "common.h"
#include "radiocontroller.h"
#include "appsettings.h"
#include "settingsdialog.h"
#include "database.h"

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    Q_DISABLE_COPY(MainWindow)

public:
    explicit MainWindow(QWidget *parent = 0);
    virtual ~MainWindow();
    bool AlreadyRunning();
    QString curFreq;
    QString ComPort;
    bool QuitIntent;
    bool PowerState; //true = ON, false = OFF

private:
    Ui::MainWindow *ui; //The window interface object
    RadioController RC; //RaidoController object
    Common COM; //Common values and data object
    AppSettings SET; //Application settings object
    Database *DB; //SQLite database object
    SettingsDialog *SETD; //Create a SettingsDialog instance
    //Status bar labels
    QLabel *lblSBLog;
    QLabel *lblSBPower;
    QLabel *lblSBPort;
    QLabel *lblSBFreq;
    QTimer* sstimer; //Signal strength update interval timer
    QTimer* hangtimer; //Scanner hang delay interval timer
    QTimer* scantimer; //Scanner channel change interval timer
    //Functions
    void LoadSettings();
    void SaveSettings();
    void createTrayIcon();
    void SetChannelFreq(QString freqstr);
    //System tray right-click context menu items
    QAction *actExit;
    QAction *actShow;
    QAction *actAbout;
    QAction *actGettingStarted;
    QAction *actMute;
    QAction *actLockout;
    QAction *actScan;
    QMenu *stiMenu; //System tray right-click context menu
    QSystemTrayIcon *ti; //System tray icon
    int LastDialVal; //Used for muting (i think)
    void ApplyPort();


protected:
    virtual void changeEvent(QEvent *e);
    virtual void closeEvent(QCloseEvent *e);

protected slots:
    void onPower();
    void onPower(bool val);
    void onShow();
    void onQuit();
    void showAbout();
    void showGettingStarted();
    void showSettings();
    void activateScanner();
    void activateScanner(bool val);
    void DirectChangeFreq();
    void DialChangeFreq(int val);
    void clicked_txtDirectTuning();
    void UpdateSignalMeter();
    void timerScanTick();
    void timerHangTick();
    void onTIclick(QSystemTrayIcon::ActivationReason reason);
    void MsgCallback(int code, QString msg);
    void ReloadSettings();
    void pressKey1();
    void pressKey2();
    void pressKey3();
    void pressKey4();
    void pressKey5();
    void pressKey6();
    void pressKey7();
    void pressKey8();
    void pressKey9();
    void pressKey0();
    void pressKeyDec();
    void pressKeyEnt();
    void clickHide();
    void clickExit();
    void clickScrollBack();
    void clickScrollForward();
    void clickAddFreq();
    void clickDelete();
    void clickResetIFShift();
    void clickBackspace();
    void clickShowChannels();
    void clickSettings();
    void changeAGC(bool val);
    void changeVSC(bool val);
    void changeAtten(bool val);
    void changeAFBlanking(bool val);
    void changeLockout();
    void changeLockout(bool val);
    void changeHangDelay();
    void changeHangDelay(bool val);
    void changeMute();
    void changeMute(bool val);
    void changeVolume(int val);
    void changeSquelch(int val);
    void changeIFShift(int val);
    void changeFilter(QString val);
    void changeMode(QString val);
};

#endif // MAINWINDOW_H
